// pages/resultslist/resultslist.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    results:{
      names:"",
      address:"",
      papersum:""
    },
    itemList:[],
    index:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (options.name == undefined){
      var url = "http://localhost:8080/IB_web_war_exploded/servlet01?area="+options.area;
      wx.request({
        url: url,
        data:{},
        method:'GET',
        header:{'Content-type':'application/x-www-form-urlencoded;'},
        success:function(res){
          var names = res.cookies[0];
          names = decodeURIComponent(names);
          var address = res.cookies[1];
          address = decodeURIComponent(address);
          var papersum = res.cookies[2];
          papersum = decodeURIComponent(papersum);
          // console.log(names);
          // console.log(address);
          // console.log(papersum);
          names = names.substring(6,names.length-3);
          var nameslis = names.split("&%@");
          console.log(nameslis);
          address = address.substring(10,address.length-3);
          var addresslis = address.split("&%@");
          console.log(addresslis);
          papersum = papersum.substring(10,papersum.length-3);
          var papersumlis = papersum.split("&%@");
          console.log(papersumlis);
          that.setData({
            ["results.names"]:names,
            ["results.address"]:address,
            ["results.papersum"]:papersum,
            index:"area:"+options.area
          })
          console.log(that.data.index);
          var b = [];
          for(var i = 0; i < nameslis.length; i++){
            var a = {};
            a["no"] = i.toString();
            a["name"] = nameslis[i];
            a["address"] = addresslis[i];
            a["pagesum"] = papersumlis[i];
            a["preindex"] = that.data.index;
            // console.log(a["name"])
            // console.log(a["address"])
            // console.log(a["pagesum"])
            b.push(a);
          };
          that.setData({
            itemList:b
          });
        },
        fail:function(res){
          console.log("请求失败！");
        }
      })
    }else{
      var url = "http://localhost:8080/IB_web_war_exploded/servlet01?name="+options.name;
      wx.request({
        url: url,
        data:{},
        method:'GET',
        header:{'Content-type':'application/x-www-form-urlencoded;'},
        success:function(res){
          var names = res.cookies[0];
          names = decodeURIComponent(names);
          var address = res.cookies[1];
          address = decodeURIComponent(address);
          var papersum = res.cookies[2];
          papersum = decodeURIComponent(papersum);
          // console.log(names);
          // console.log(address);
          // console.log(papersum);
          names = names.substring(6,names.length-3);
          var nameslis = names.split("&%@");
          console.log(nameslis);
          address = address.substring(10,address.length-3);
          var addresslis = address.split("&%@");
          console.log(addresslis);
          papersum = papersum.substring(10,papersum.length-3);
          var papersumlis = papersum.split("&%@");
          console.log(papersumlis);
          that.setData({
            ["results.names"]:names,
            ["results.address"]:address,
            ["results.papersum"]:papersum,
            index:"name:"+options.name
          })
          console.log(that.data.index);
          var b = [];
          for(var i = 0; i < nameslis.length; i++){
            var a = {};
            a["no"] = i.toString();
            a["name"] = nameslis[i];
            a["address"] = addresslis[i];
            a["pagesum"] = papersumlis[i];
            a["preindex"] = that.data.index;
            // console.log(a["name"])
            // console.log(a["address"])
            // console.log(a["pagesum"])
            b.push(a);
          };
          that.setData({
            itemList:b
          });

        },
        fail:function(res){
          console.log("请求失败！");
        }
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  turntosingle:function(e){
    console.log(e.target.id);
    wx.navigateTo({
      url: '../singleresult/singleresult?index='+e.target.id,
    })
  }
})